home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / test_true.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  90 lines

  1. ; $Id: test_true.pro,v 1.2 1996/12/17 01:21:43 ali Exp $
  2.  
  3. ;
  4. ;    Procedure to test IDL true color operation
  5. ;
  6. function col,r,g,b    ;Return the color index, given R, G, and B
  7. return,r + 256L*(g + 256L*b)
  8. end
  9.  
  10. pro test_true
  11.  
  12. Print, 'Demonstration of True Color / IDL'
  13. Read,'Enter 1 for retained windows, 0 for non-retained: ',retain
  14. window,xs=512,ys=800,retain=retain    ;Make a window
  15.  
  16. print,'Ramps'
  17. v = [0,0,0]
  18. for ic=0,2 do begin
  19.   for iy=0,255 do begin    ;Fill with vectors of 3 colors
  20.     v = intarr(3)
  21.     v[ic] = iy
  22.     y = ic*256 + iy
  23.     plots,[0,511],[y,y],/dev,col=col(v[0],v[1],v[2])
  24.     endfor
  25.    empty
  26. endfor
  27.  
  28. ; Make an image and output to Channels 0 thru 3.  Channel 0 is all channels.
  29. ; Then, read it back and compare.
  30. print,'Output an image to all channels, then r,g,b'
  31. a=bytscl(dist(200))
  32. for i=0,3 do begin
  33.     tv,a,i*100,i*100,channel=i    ;Write it
  34.     empty
  35.     b = tvrd(i*100,i*100,200,200,channel=i) ;Read it
  36.     if total(abs(a-b)) ne 0 then $
  37.       print, "Read Compare Error, Channel ",i
  38.     endfor
  39.  
  40. Print,'Color Table Manipulations'
  41. for i=0,15 do begin loadct,i,/silent & wait,0.5  & end
  42. r = indgen(256)
  43. s = [1,1,1]
  44. for j=0,2 do begin
  45.     for i=0,256,2 do begin
  46.     tvlct,shift(r,i*s[0]),shift(r,i*s[1]),shift(r,i*s[2])
  47.     wait,.01
  48.     endfor
  49.   s[j] = -1
  50. endfor
  51. loadct,0,/silent
  52.  
  53. print,'Reading image'
  54. close,1
  55.  
  56. fname = filepath('p077h3b.equ',subdir='images') ;the demo true color image 
  57. qq = findfile(fname,count = i)
  58. if i eq 0 then begin
  59.     print,'Cant find true color image file ',fname
  60.     print,'Skipping this part of the demo.'
  61.     goto, no_file
  62.     endif
  63. openr,1, fname
  64. a=bytarr(500,500,4)
  65. readu,1,a
  66. close,1
  67.  
  68. print,'Displaying Image'
  69. erase
  70. tv,a,true=3    ;Output 1st three images of A into R,G,B
  71. wait,1
  72. tv,a[*,*,3],channel=2    ;Output Fourth into Green channel
  73.  
  74. no_file: 
  75. print,'Computing Hue-Saturation Image'
  76. siz = 150
  77. x = indgen(siz) # replicate(1,siz) - siz/2.
  78. y = replicate(1,siz) # indgen(siz) - siz/2.
  79. r = sqrt(x^2 + y^2) / (siz/2.) < 1 ;From 0 to 1.
  80. hue = atan(y,x) * (180./!pi)
  81. color_convert,hue, r, replicate(1.,siz,siz), r,g,b,/hsv_rgb
  82.  
  83. print,'Displaying Hue-Saturation Image'
  84. tv,r,0,channel=1
  85. tv,g,0,channel=2
  86. tv,b,0,channel=3
  87.  
  88. print,'Done'
  89. end
  90.